package com.zenithmind.chat.service;

import com.zenithmind.chat.pojo.dto.AiChatDTO;
import com.zenithmind.chat.pojo.dto.AiChatMessageDTO;
import com.zenithmind.chat.pojo.entity.AiChat;

/**
 * AI对话验证服务接口
 * 遵循单一职责原则，专门负责数据验证
 */
public interface AiChatValidationService {
    
    /**
     * 验证对话创建数据
     * 
     * @param chatDTO 对话DTO
     * @return 验证结果
     */
    ValidationResult validateChatCreation(AiChatDTO chatDTO);
    
    /**
     * 验证对话更新数据
     * 
     * @param chat 现有对话
     * @param chatDTO 更新数据
     * @return 验证结果
     */
    ValidationResult validateChatUpdate(AiChat chat, AiChatDTO chatDTO);
    
    /**
     * 验证消息发送数据
     * 
     * @param messageDTO 消息DTO
     * @return 验证结果
     */
    ValidationResult validateMessageSend(AiChatMessageDTO messageDTO);
    
    /**
     * 验证对话配置
     * 
     * @param chat 对话实体
     * @return 验证结果
     */
    ValidationResult validateChatConfiguration(AiChat chat);
    
    /**
     * 验证结果类 - 遵循单一职责原则
     */
    class ValidationResult {
        private final boolean valid;
        private final String errorMessage;
        private final int errorCode;

        public ValidationResult(boolean valid, String errorMessage, int errorCode) {
            this.valid = valid;
            this.errorMessage = errorMessage;
            this.errorCode = errorCode;
        }

        public static ValidationResult success() {
            return new ValidationResult(true, null, 200);
        }

        public static ValidationResult failure(String errorMessage) {
            return new ValidationResult(false, errorMessage, 400);
        }

        public static ValidationResult failure(int errorCode, String errorMessage) {
            return new ValidationResult(false, errorMessage, errorCode);
        }

        public boolean isValid() {
            return valid;
        }

        public String getErrorMessage() {
            return errorMessage;
        }

        public int getErrorCode() {
            return errorCode;
        }

        /**
         * 如果验证失败，抛出异常
         */
        public void throwIfInvalid() {
            if (!valid) {
                throw new com.zenithmind.chat.exception.AiChatException(errorCode, errorMessage);
            }
        }
    }
}
